﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace JzSport.Api
{
    /// <summary>
    /// 审核加入活动申请
    /// </summary>
    class AuditingJoinActivityRequestAction : AuthPostAction<AuditingJoinActivityRequestParams,
        AuditingJoinActivityRequestResult>
    {
        protected override ActionResult<AuditingJoinActivityRequestResult> OnExecute(ActionContext context, SysParameters sysParameters,
            AuditingJoinActivityRequestParams opParams)
        {
            AuditingJoinActivityRequestResult actionResult = new AuditingJoinActivityRequestResult();
            if (opParams.Method == 1)
            {
                // 通过
                ServiceResult<ActivityMember> serviceResult = new ActivityService().AcceptJoinRequest(opParams.TargetUserId,
                    opParams.ActivityId);

                if (serviceResult.ErrorCode == ErrorCode.NoError)
                {
                    return new ActionResult<AuditingJoinActivityRequestResult>("1.0", true, serviceResult.ErrorCode,
                        ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
                }
                return new ActionResult<AuditingJoinActivityRequestResult>("1.0", false, serviceResult.ErrorCode,
                        ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            else if (opParams.Method == 0)
            {
                //  不通过
                ServiceResult<string> serviceResult = new ActivityService().RejectJoinRequest(opParams.TargetUserId,
                    opParams.ActivityId);

                if (serviceResult.ErrorCode == ErrorCode.NoError)
                {
                    return new ActionResult<AuditingJoinActivityRequestResult>("1.0", true, serviceResult.ErrorCode,
                        ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
                }
                return new ActionResult<AuditingJoinActivityRequestResult>("1.0", false, serviceResult.ErrorCode,
                        ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<AuditingJoinActivityRequestResult>("1.0", false, ErrorCode.Common_InvalidParameter,
                    ErrorCode.ToString(ErrorCode.Common_InvalidParameter), actionResult);
        }
    }

    public class AuditingJoinActivityRequestResult
    {
    }

    public class AuditingJoinActivityRequestParams : IActionParams
    {
        public Guid ActivityId { get; set; }
        public int TargetUserId { get; set; }
        public int Method { get; set; }

        public void ParseQueryString(HttpRequest request)
        {
            this.ActivityId = new Guid(request.QueryString["op:activityid"]);
            this.TargetUserId = Convert.ToInt32(request.QueryString["op:TargetUserId"]);
            this.Method = Convert.ToInt32(request.QueryString["op:Method"]);
        }

        public void ParseForm(HttpRequest request)
        {
            this.ActivityId = new Guid(request.Form["op:activityid"]);
            this.TargetUserId = Convert.ToInt32(request.Form["op:TargetUserId"]);
            this.Method = Convert.ToInt32(request.Form["op:Method"]);
        }
    }
}
